Skip to content

fix(node,gnn): ESM import of @ruvector/node resolves; TensorCompress input no longer aborts Node (@ruvector/node 0.1.25) - #1335

Merged
ruvnet merged 2 commits into
mainfrom
fix/ruvector-node-review-2026-11-04
Nov 4, 2026
Merged

ruvnet merged 2 commits into
mainfrom
fix/ruvector-node-review-2026-11-04

Conversation

@ruvnet

@ruvnet ruvnet commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Review of @ruvector/node 0.1.24 (npm) and the native code it re-exports.

Fixes

1. ESM import of @ruvector/node fails for everyone (HIGH) — npm/packages/node/package.json
exports[".|./gnn"].import and module pointed at dist/index.mjs / dist/gnn.mjs, which the build never produced. The ESM and CJS tsc passes shared outDir, so CJS overwrote ESM. import { VectorDB } from '@ruvector/node' → ERR_MODULE_NOT_FOUND on the published tarball; only require worked.
Now the package is CJS-only: every condition points at dist/*.js, with types first. A real ESM build would not help, because @ruvector/core sets module.exports = nativeModule, so Node cannot statically see its named exports. The single tsc pass now emits the .d.ts files. dist/ is byte-identical to the published 0.1.24. Bumped to 0.1.25.
Added test/exports.test.mjs (node --test ran 0 tests before): 4/5 failed before the fix, 5/5 pass after. Also checked from a packed tarball in a fresh "type":"module" consumer: runtime import works, and tsc passes under nodenext and bundler.

2. TensorCompress input aborts the Node process (HIGH) — crates/ruvector-gnn/src/compress.rs
These are re-exported from @ruvector/node, and each one SIGABRTs the process instead of throwing:

  • compressWithLevel(e, {levelType:'pq8'|'pq4', subvectors:0}) hits an expect on checked_rem.
  • decompress(json) with subvector_dim: 0 divides by zero. The JSON is caller-supplied or stored data.
  • decompress allocated dim floats from that JSON before validating anything, so subvector_dim = dim = 2^40 asked for 4 TB. A mismatch between the codes and codebooks counts silently returned a short vector.
  • Still open: centroids: 0 compresses to a tensor that decompress rejects. That is a silent, undecodable result rather than an abort.
  • napi CompressionLevelConfig: subvectors/centroids as u8 wrapped (256 → 0). Values above 255 are now rejected.

Red tests: the Rust units in compress.rs and subprocess JS tests in crates/ruvector-gnn-node/test/dimensions.test.js both SIGABRT on the published @ruvector/gnn 0.1.25 binary and pass on this build. cargo test -p ruvector-gnn passes 229/229, gnn JS tests 61/61, and clippy is clean for the touched code.

Not changed (other lanes / packages)

Publish (not done here)

  1. @ruvector/node: cd npm/packages/node && npm install && npm run build && npm test && npm publish (prepublishOnly builds; needs typescript installed). It has no optionalDependencies, so optional-deps-resolvable-on-npm is unaffected.
  2. @ruvector/gnn: bump crates/ruvector-gnn-node/package.json version and the optionalDependencies pins to 0.1.26 in one commit, then run build-gnn.yml with workflow_dispatch and publish=true from that commit. That workflow publishes the platform packages before the main one. optional-deps-resolvable-on-npm only scans npm/packages, so gnn is outside its scope. @ruvector/node's ^0.1.15 range picks up 0.1.26 automatically.

🤖 Generated with claude-flow

package.json pointed the "import" condition and "module" field at
dist/index.mjs and dist/gnn.mjs, but the build never emitted them: the
ESM and CJS tsc passes shared outDir, so the CJS pass overwrote the ESM
output. Every `import ... from '@ruvector/node'` (and './gnn') failed
with ERR_MODULE_NOT_FOUND; only require() worked.

Ship CJS only and route all conditions to it, with "types" first. A real
ESM build would not help: @ruvector/core assigns module.exports from the
native addon, so cjs-module-lexer cannot see its named exports. Node's
CJS interop gives ESM callers named and default exports from dist/*.js.

The single remaining tsc pass now emits the .d.ts files the ESM pass used
to produce; dist output is byte-identical to 0.1.24 apart from the map.

Adds test/exports.test.mjs (node --test previously ran zero tests).

Co-Authored-By: claude-flow <ruv@ruv.net>
@ruvector/node re-exports TensorCompress from @ruvector/gnn. Three
JS-reachable paths panicked inside the addon, which aborts the whole
Node process (SIGABRT, "failed to initiate panic") instead of throwing:

- compressWithLevel({levelType: 'pq8'|'pq4', subvectors: 0}) hit an
  `expect` on checked_rem in compress_pq8/compress_pq4.
- decompress(json) of a PQ8/PQ4 tensor with subvector_dim 0 divided by
  zero. decompress parses caller-supplied (e.g. stored) JSON.
- decompress also pre-allocated `dim` floats from that JSON before
  validating any code, so {codes:[0], codebooks:[[]], subvector_dim:
  2^40, dim: 2^40} requested a 4 TB buffer. A codes/codebooks length
  mismatch silently returned a short vector.

PQ layouts are now validated (non-zero subvector_dim, matching code and
codebook counts, checked dim product, every centroid index in range)
before allocating, so output size is bounded by the input. The napi
wrapper rejects subvectors/centroids > 255 instead of wrapping via
`as u8` (256 became 0).

Red tests: Rust unit tests in compress.rs and subprocess JS tests in
crates/ruvector-gnn-node/test/dimensions.test.js (both SIGABRT against
the published @ruvector/gnn 0.1.25 binary, pass on this build).

Co-Authored-By: claude-flow <ruv@ruv.net>
@ruvnet
ruvnet merged commit 0dc39ca into main Nov 4, 2026
62 checks passed
ruvnet added a commit that referenced this pull request Nov 4, 2026
Per-crate version overrides (workspace 2.3.0 is already published):
- ruvector-rabitq 2.3.0 -> 2.3.1 (#1325)
- ruvector-cnn 2.3.0 -> 2.3.1 (#1336)
- ruvector-gnn 2.3.0 -> 2.3.1 (#1335)
- ruvector-tiny-dancer-core 2.3.0 -> 2.3.1 (#1321)
- ruvector-graph 2.3.2 -> 2.3.3 (#1331)
- ruvector-graph-wasm 2.3.0 -> 2.3.1 (#1331)
- ruvector-gnn-node 2.3.0 -> 2.3.1 (#1335)

Dependent reqs raised so the published wasm/node crates pull the fixed cores:
rabitq-wasm -> rabitq 2.3.1, cnn-wasm -> cnn 2.3.1, graph-wasm -> graph 2.3.3,
gnn-node -> gnn 2.3.1. ruvector-rabitq-wasm 0.1.1, ruvector-cnn-wasm 0.1.1 and
ruvllm-wasm 2.0.4 keep their already-unpublished repo versions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant